


<!DOCTYPE html>
<html id="htmlId">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
  <title>Coverage Report > LibraryService</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">com.llsly.library.service</a>
</div>

<h1>Coverage Summary for Class: LibraryService (com.llsly.library.service)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Branch, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LibraryService</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    85.7%
  </span>
  <span class="absValue">
    (6/7)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    70%
  </span>
  <span class="absValue">
    (7/10)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    94.1%
  </span>
  <span class="absValue">
    (16/17)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package com.llsly.library.service;
&nbsp;
&nbsp;import com.llsly.library.model.Book;
&nbsp;import com.llsly.library.repository.BookRepository;
&nbsp;import org.springframework.beans.factory.annotation.Autowired;
&nbsp;import org.springframework.stereotype.Service;
&nbsp;
&nbsp;import java.util.Optional;
&nbsp;
&nbsp;@Service
<b class="fc">&nbsp;public class LibraryService {</b>
&nbsp;    @Autowired
&nbsp;    private BookRepository bookRepository;
&nbsp;
&nbsp;    // 添加书籍
&nbsp;    public Book addBook(Book book) {
<b class="fc">&nbsp;        return bookRepository.save(book);</b>
&nbsp;    }
&nbsp;
&nbsp;    // 移除书籍
&nbsp;    public void removeBook(Long id) {
<b class="fc">&nbsp;        if (!bookRepository.existsById(id)) {</b>
<b class="fc">&nbsp;            throw new IllegalArgumentException(&quot;书籍ID不存在: &quot; + id);</b>
&nbsp;        }
<b class="fc">&nbsp;        bookRepository.deleteById(id);</b>
&nbsp;    }
&nbsp;
&nbsp;    // 获取书籍数量
&nbsp;    public long getBookCount() {
<b class="nc">&nbsp;        return bookRepository.count();</b>
&nbsp;    }
&nbsp;
&nbsp;    // 检查是否有指定书名的书
&nbsp;    public boolean hasBook(String title) {
<b class="fc">&nbsp;        return bookRepository.findByTitle(title) != null;</b>
&nbsp;    }
&nbsp;
&nbsp;    // 更新书籍信息
&nbsp;    public Book updateBook(Long id, Book updatedBook) {
<b class="fc">&nbsp;        return bookRepository.findById(id)</b>
<b class="fc">&nbsp;                .map(existingBook -&gt; {</b>
<b class="pc">&nbsp;                    if (updatedBook.getTitle() != null) {</b>
<b class="fc">&nbsp;                        existingBook.setTitle(updatedBook.getTitle());</b>
&nbsp;                    }
<b class="pc">&nbsp;                    if (updatedBook.getAuthor() != null) {</b>
<b class="fc">&nbsp;                        existingBook.setAuthor(updatedBook.getAuthor());</b>
&nbsp;                    }
<b class="pc">&nbsp;                    if (updatedBook.getIsbn() != null) {</b>
<b class="fc">&nbsp;                        existingBook.setIsbn(updatedBook.getIsbn());</b>
&nbsp;                    }
<b class="fc">&nbsp;                    return bookRepository.save(existingBook);</b>
&nbsp;                })
<b class="fc">&nbsp;                .orElseThrow(() -&gt; new IllegalArgumentException(&quot;书籍ID不存在: &quot; + id));</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2025-05-04 13:53</div>
</div>
</body>
</html>
